<?php
    require ('../../classes/GalleryManager.class.php');
    
    $gm = new GalleryManager();
    $g = new Gallery();
    
    $g->title = isset($_POST['title']) ? $_POST['title'] : 'Galleria senza titolo';
    $g->description = isset($_POST['description']) ? $_POST['description'] : '';
    $g->date = new DateTime(isset($_POST['date']) ? $_POST['date'] : 'now');
    $g->path = isset($_POST['foldername']) ? $_POST['foldername'] : '';
    $g->creator = $_POST['uid'];
    $g->folder = isset($_POST['folder']) ? $_POST['folder'] : '';;
    $gm->save_gallery($g);
    
    $result = array('gallery_id' => $g->id,
                    'year' => $g->date->format('Y'),
                    'month' => $g->date->format('m'),
                    'foldername' => $g->path
                   );
    
    echo json_encode($result);
?>
